package com.cat.greedyAlgorithm;

/**
 *   @description https://leetcode.cn/problems/jump-game-ii/?envType=study-plan-v2&envId=top-100-liked
 *   @author 曲大人的喵
 *   @create 2025/9/24 21:07
 *   @since JDK17
 */

public class Solution44 {
    public int jump(int[] nums) {
        int max = nums[0], ans = 1, n = nums.length - 1, h = max;
        if (n == 0) {
            return 0;
        }
        for (int i = 0; i < n && max < n; i++) {
            h = Math.max(h, i + nums[i]);
            if (i == max) {
                max = h;
                ans++;
            }
        }

        return ans;
    }
}
